//
//  PayResultViewController.m
//  PigMarket
//
//  Created by mac on 2019/4/9.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "PayResultViewController.h"
#import "MyAdoptedViewController.h"

@interface PayResultViewController ()
/**
 整体bg
 */
@property (nonatomic , strong) UIView *bgView;
/**
 头像
 */
@property (nonatomic , strong) UIImageView *headerImgView;
/**
 品种
 */
@property (nonatomic , strong) UILabel *varietyLab;
/**
 编号
 */
@property (nonatomic , strong) UILabel *numLab;
/**
 支付结果
 */
@property (nonatomic , strong) UILabel *payResultLab;
/**
 支付金额
 */
@property (nonatomic , strong) YYLabel *payPriceLab;
/**
 支付详细金额
 */
@property (nonatomic , strong) UILabel *payDetailPrice;
/**
 查看领养
 */
@property (nonatomic , strong) UIButton *checkAdoptedBtn;
/**
 回到首页
 */
@property (nonatomic , strong) UIButton *backHomeBtn;
/**
 对号图片
 */
@property (nonatomic , strong) UIImageView *resultImageView;
/**
 结果提示
 */
@property (nonatomic , strong) UILabel *resultTips;
/**
 topLine
 */
@property (nonatomic , strong) UIImageView *topLine;
/**
 bottomLine
 */
@property (nonatomic , strong) UIImageView *bottomLine;
@end

@implementation PayResultViewController

#pragma mark - view life cycle

- (void)viewDidLoad {
    [super viewDidLoad];
    self.baseNavView.navTitleLabel.text = @"支付成功";
    [self setUpView];
}


#pragma mark - init method

- (void)setUpView {
    [self initView];
    [self initLayout];
    [self initAction];
    [self initData];
}


- (void)initView {
    [self.view addSubview:self.bgView];
    [self.view addSubview:self.headerImgView];
    [self.bgView addSubview:self.varietyLab];
    [self.bgView addSubview:self.numLab];
    [self.bgView addSubview:self.topLine];
    [self.bgView addSubview:self.payResultLab];
    [self.bgView addSubview:self.payPriceLab];
    [self.bgView addSubview:self.backHomeBtn];
    [self.bgView addSubview:self.bottomLine];
    [self.bgView addSubview:self.resultImageView];
    [self.bgView addSubview:self.resultTips];
}


- (void) initLayout {
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(73 +TJ_NavBarHeight);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(500);
    }];
    
    [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30 + TJ_NavBarHeight);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(105, 105));
    }];
    [self.varietyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
        make.top.mas_equalTo(self.headerImgView.mas_bottom).offset(16);
        make.height.mas_equalTo(24);
    }];
    [self.numLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.varietyLab.mas_bottom).offset(5);
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
        make.height.mas_equalTo(20);
    }];
    [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgView.mas_top).offset(132);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
    }];
    [self.payResultLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topLine.mas_bottom).offset(30);
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
        make.height.mas_equalTo(32);
    }];
    [self.payPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.payResultLab.mas_bottom).offset(9);
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
    }];
    
    [self.backHomeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.payPriceLab.mas_bottom).offset(32);
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(126, 36));
    }];
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topLine.mas_bottom).offset(173);
        make.left.right.mas_equalTo(0);
    }];
    [self.resultImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bottomLine.mas_bottom).offset(20);
        make.centerX.mas_equalTo(self.bgView.mas_centerX);
        make.width.height.mas_equalTo(60);
    }];
    [self.resultTips mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.resultImageView.mas_bottom).offset(10);
        make.left.mas_equalTo(36);
        make.right.mas_equalTo(-36);
    }];
    
}


- (void) initAction {
    [self.backHomeBtn addTarget:self action:@selector(goLook) forControlEvents:UIControlEventTouchUpInside];
}


- (void)initData {
    
    [self.headerImgView sd_setImageWithURL:[NSURL URLWithString:self.model.pigHeadImg] placeholderImage:[UIImage imageNamed:@"placeholder_middle"]];
    self.varietyLab.text = self.model.varietiesName;
    self.numLab.text = [NSString stringWithFormat:@"仔猪的编号%@",self.model.pigNum];
    self.payResultLab.text = @"支付成功";
    NSString *titleStr = [NSString stringWithFormat:@"您已成功支付:%@元",self.actuallyPaymentMoney];
    NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:titleStr];
    text.yy_font = [UIFont systemFontOfSize:13];;
    text.yy_color = [UIColor tipsGrayColor];
    text.yy_alignment = NSTextAlignmentCenter;
    [text yy_setFont:[UIFont largerFont] range:NSMakeRange(7, titleStr.length - 7)];
    [text yy_setColor:[UIColor colorWithHexString:@"#F25C62"] range:NSMakeRange(7, titleStr.length - 7)];
    self.payPriceLab.attributedText = text;

    self.resultTips.text = @"支付成功相关提示内容支付成功相关提示内容支付成功相关提示内容v";
}


#pragma mark - delegate

#pragma mark - target action
- (void) goLook{
    
    __block BOOL isHave = NO;
    [self.navigationController.childViewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if ([obj isKindOfClass:[MyAdoptedViewController class]]) {
            isHave = YES;
            [self.navigationController popToViewController:obj animated:YES];
        }
    }];
    
    if (!isHave) {
        MyAdoptedViewController *vc = [[MyAdoptedViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}


#pragma mark - private method

#pragma mark - getter and setter
- (UIView *)bgView {
    if (!_bgView) {
        _bgView  = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 12;
        _bgView.layer.shadowOffset = CGSizeMake(0, 0);
        _bgView.layer.shadowRadius = 12;
        _bgView.layer.shadowColor = [UIColor colorWithRed:217/255.0 green:226/255.0 blue:233/255.0 alpha:0.5].CGColor;
        _bgView.layer.shadowOpacity = 1;
    }
    return _bgView;
}


- (UIImageView *)headerImgView {
    
    if (!_headerImgView) {
        _headerImgView  = [[UIImageView alloc] init];
        _headerImgView.image = [UIImage imageNamed:@"placeholder_small"];
        [self addShadowAndCircleCorner:_headerImgView.layer corner:52.5];
    }
    return _headerImgView;
}


- (UILabel *)varietyLab {
    if (!_varietyLab) {
        _varietyLab = [[UILabel alloc] init];
        _varietyLab.textColor = [UIColor textBlackColor];
        _varietyLab.font = [UIFont systemFontOfSize:17];
        _varietyLab.textAlignment = NSTextAlignmentCenter;
    }
    return _varietyLab;
}


- (UILabel *)numLab {
    if (!_numLab) {
        _numLab = [[UILabel alloc] init];
        _numLab.textColor = [UIColor colorWithHexString:@"#8D8D8D"];
        _numLab.font = [UIFont middleFont];
        _numLab.textAlignment = NSTextAlignmentCenter;

    }
    return _numLab;
}


- (UILabel *)payResultLab {
    if (!_payResultLab) {
        _payResultLab = [[UILabel alloc] init];
        _payResultLab.textColor = [UIColor textBlackColor];
        _payResultLab.font = [UIFont systemFontOfSize:23];
        _payResultLab.textAlignment = NSTextAlignmentCenter;
        
    }
    return _payResultLab;
}


- (YYLabel *)payPriceLab {
    if (!_payPriceLab) {
        _payPriceLab = [[YYLabel alloc] init];
    }
    return _payPriceLab;
}

- (UIButton *)backHomeBtn {
    if (!_backHomeBtn) {
        _backHomeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backHomeBtn setTitle:@"去看看" forState:UIControlStateNormal];
        [_backHomeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _backHomeBtn.titleLabel.font = [UIFont largerFont];
        [_backHomeBtn setBackgroundImage:[UIImage imageNamed:@"pay_result_btn_bg"] forState:UIControlStateNormal];
        [self addShadowAndCircleCorner:_backHomeBtn.layer corner:18];

    }
    return _backHomeBtn;
}


- (UIImageView *)resultImageView {
    if (!_resultImageView) {
        _resultImageView = [[UIImageView alloc] init];
        _resultImageView.image = [UIImage imageNamed:@"meat_complaints_selected"];
    }
    return _resultImageView;
}


- (UILabel *)resultTips {
    if (!_resultTips) {
        _resultTips = [[UILabel alloc] init];
        _resultTips.textColor = [UIColor tipsGrayColor];
        _resultTips.font = [UIFont systemFontOfSize:13];
        _resultTips.numberOfLines = 0;
        _resultTips.textAlignment = NSTextAlignmentCenter;
    }
    return _resultTips;
}


- (UIImageView *)topLine {
    if (!_topLine) {
        _topLine = [[UIImageView alloc] init];
        _topLine.image = [UIImage imageNamed:@"pay_result_line"];
    }
    return _topLine;
}


- (UIImageView *)bottomLine {
    if (!_bottomLine) {
        _bottomLine = [[UIImageView alloc] init];
        _bottomLine.image = [UIImage imageNamed:@"pay_result_line"];
    }
    return _bottomLine;
}


@end
